package com.my.demo.demo2.util;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author shanchong
 * @date 2019-07-11
 **/
public class XmlUtil {

    public static Map<String, String> xml2Map(String xml) throws DocumentException {
        Map<String, String> rest = new HashMap<String, String>();
        Document rootDoc = DocumentHelper.parseText(xml);
        List<Element> els = rootDoc.getRootElement().elements();
        for(Element el : els){
            rest.put(el.getName().toLowerCase(), el.getTextTrim());
        }
        return rest;
    }

}
